/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.imsx.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 *
 * @author mivkys
 */
public class Orden {

    private String ordenId;
    private String compradorId;
    private Map<String,Item> items;
    private Double total;
    private Date fechaCompra;

    public Orden(String ordenId) {
        items = new HashMap<String,Item>();
        this.ordenId = ordenId;
        this.fechaCompra = new Date();
        this.compradorId = null;
        total();
    }
    public Orden(String ordenId, Map<String,Item> items, Date date) {
        this.items = items;
        this.ordenId = ordenId;
        this.fechaCompra = date;
        this.compradorId = null;
        total();
    }
    /**
     * @return the ordenId
     */
    public String getOrdenId() {
        return ordenId;
    }

    /**
     * @param ordenId the ordenId to set
     */
    public void setOrdenId(String ordenId) {
        this.ordenId = ordenId;
    }

    /**
     * @return the compradorId
     */
    public String getCompradorId() {
        return compradorId;
    }

    /**
     * @param compradorId the compradorId to set
     */
    public void setCompradorId(String compradorId) {
        this.compradorId = compradorId;
    }

    /**
     * @return the items
     */
    public Map<String,Item> getItems() {
        return items;
    }

    /**
     * @param items the items to set
     */
    public void setItems(Map<String,Item> items) {
        this.items = items;
    }
//    public void setItems(Item item) {
//        this.items.put(item.getItemId(),item);
//    }
    /**
     * @return the total
     */
    public Double getTotal() {
        total();
        return total;
    }

    /**
     * @param total the total to set
     */
    public void setTotal(Double total) {
        this.total = total;
    }

    /**
     * @return the fechaCompra
     */
    public Date getFechaCompra() {
        return fechaCompra;
    }

    /**
     * @param fechaCompra the fechaCompra to set
     */
    public void setFechaCompra(Date fechaCompra) {
        this.fechaCompra = fechaCompra;
    }
    private void total(){
        total = 0.0;
        Iterator it = items.keySet().iterator();
        while(it.hasNext()){
            String key = it.next().toString();
            total +=items.get(key).getPrecioTotal();
        }
    }
}
